<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>接受由 stream_socket_server 创建的套接字连接</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.stream-set-write-buffer.html">« stream_set_write_buffer</a></li>
      <li style="float: right;"><a href="function.stream-socket-client.html">stream_socket_client »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.stream.html">Stream 函数</a></li>
    <li>接受由 stream_socket_server 创建的套接字连接</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.stream-socket-accept" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_socket_accept</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stream_socket_accept</span> &mdash; <span class="dc-title">接受由 <span class="function"><a href="function.stream-socket-server.html" class="function">stream_socket_server()</a></span> 创建的套接字连接</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stream-socket-accept-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stream_socket_accept</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">float</span><span class="type"></span></span> <code class="parameter">$timeout</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$peer_name</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">resource</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   接受由 <span class="function"><a href="function.stream-socket-server.html" class="function">stream_socket_server()</a></span> 创建的套接字连接。
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.stream-socket-accept-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">socket</code></dt>

     <dd>

      <p class="para">
       需要接受的服务器创建的套接字连接。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">timeout</code></dt>

     <dd>

      <p class="para">
       覆盖默认的套接字接受的超时时限。输入的时间需以秒为单位。默认情况下，使用
       <a href="filesystem.configuration.html#ini.default-socket-timeout" class="link">default_socket_timeout</a>
       作为超时时限。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">peer_name</code></dt>

     <dd>

      <p class="para">
       如果已选的传输器存在且有效的已连接客户端，则将该值设置为已连接客户端名称（地址）。
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        也可以之后通过 <span class="function"><a href="function.stream-socket-get-name.html" class="function">stream_socket_get_name()</a></span> 来确定。
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-socket-accept-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回接受套接之后的资源流  或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stream-socket-accept-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       现在 <code class="parameter">timeout</code> 可以为 null。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 notes" id="refsect1-function.stream-socket-accept-notes">
  <h3 class="title">注释</h3>
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
    该函数不能被用于 UDP 套接字。可以使用 <span class="function"><a href="function.stream-socket-recvfrom.html" class="function">stream_socket_recvfrom()</a></span> 和
    <span class="function"><a href="function.stream-socket-sendto.html" class="function">stream_socket_sendto()</a></span> 来取而代之。
   </p>
 </div>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.stream-socket-accept-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.stream-socket-server.html" class="function" rel="rdfs-seeAlso">stream_socket_server()</a> - 创建 Internet 或 Unix 域服务器套接字</span></li>
    <li class="member"><span class="function"><a href="function.stream-socket-get-name.html" class="function" rel="rdfs-seeAlso">stream_socket_get_name()</a> - 获取本地或者远程的套接字名称</span></li>
    <li class="member"><span class="function"><a href="function.stream-set-blocking.html" class="function" rel="rdfs-seeAlso">stream_set_blocking()</a> - 为资源流设置阻塞或者阻塞模式</span></li>
    <li class="member"><span class="function"><a href="function.stream-set-timeout.html" class="function" rel="rdfs-seeAlso">stream_set_timeout()</a> - Set timeout period on a stream</span></li>
    <li class="member"><span class="function"><a href="function.fgets.html" class="function" rel="rdfs-seeAlso">fgets()</a> - 从文件指针中读取一行</span></li>
    <li class="member"><span class="function"><a href="function.fgetss.html" class="function" rel="rdfs-seeAlso">fgetss()</a> - 从文件指针中读取一行并过滤掉 HTML 标记</span></li>
    <li class="member"><span class="function"><a href="function.fwrite.html" class="function" rel="rdfs-seeAlso">fwrite()</a> - 写入文件（可安全用于二进制文件）</span></li>
    <li class="member"><span class="function"><a href="function.fclose.html" class="function" rel="rdfs-seeAlso">fclose()</a> - 关闭一个已打开的文件指针</span></li>
    <li class="member"><span class="function"><a href="function.feof.html" class="function" rel="rdfs-seeAlso">feof()</a> - 测试文件指针是否到了文件结束的位置</span></li>
    <li class="member"><a href="ref.curl.html" class="xref">cURL 函数</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>